package org.elanfox.intellicommunity.intellicommunityadmin.controller.alarm;

import org.elanfox.intellicommunity.biz.entity.resident.WorkerPO;
import org.elanfox.intellicommunity.biz.service.core.alarm.AlarmManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;
import java.util.Map;

/**
 * @author allan
 * @version 1.0.0
 * @date 1/27/21
 */
@Controller
@RequestMapping("/alarm/manage")
public class AlarmManageController {
    @Autowired
    private AlarmManageService alarmManageService;

    @GetMapping("/list/{userId}")
    public String list(@PathVariable("userId") int userId, Model model) {
        Map<Integer, List<WorkerPO>> results = alarmManageService.findNearBy(userId);

        model.addAttribute("results", results);
        int type = 0;
        if (results.keySet().stream().anyMatch(p -> p > 0)) {
            type = 1;
        }
        model.addAttribute("type", type);

        return "manage/stewards_near_by";
    }

}
